#include "filter_text_edit.h"

filter_highlighter::filter_highlighter ( QString key_words , QTextEdit * parent )
:QSyntaxHighlighter(parent),KeyWords(key_words)
{
}
void filter_highlighter::highlightBlock(const QString &text)
{
    QTextCharFormat myClassFormat;
    myClassFormat.setFontWeight(QFont::Bold);
    myClassFormat.setForeground(Qt::darkMagenta);
    QString pattern = "\\b"+KeyWords+"\\b";

    QRegExp expression(pattern);
    int index = text.indexOf(expression);
    while (index >= 0) {
        int length = expression.matchedLength();
        setFormat(index, length, myClassFormat);
        index = text.indexOf(expression, index + length);
    }
}


filter_text_edit::filter_text_edit(QWidget * parent/* = 0*/) 
:QTextEdit(parent)
{

}

void filter_text_edit::keyPressEvent ( QKeyEvent * e )  
{
    if(e->key() == Qt::Key_Return)
    {
        e->ignore() ;
        emit filter_set() ; 
    }
    else
        QTextEdit::keyPressEvent(e) ;
}
